package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/callThePolice")
public class AlarmInformationController {

    @GetMapping("/message")
    public void c(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject = new JSONObject();
        JSONObject json = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();

//        JSONArray Array = new JSONArray();
//        jsonObject.put("instruction","updatepoi");
//        json.put("updatetype","reset");
//        json.put("poigroup","baojing");
//        json.put("poitype","baojing");
//
//        xinxi1.put("位号", "GDS_A_AT_0004"); // GN  位号  1
//        xinxi1.put("报警级别", "低报");   // AL  报警优先级  5
//        xinxi1.put("读值", "19.91");  // AV  值  2
//        xinxi1.put("计量单位", "℃");
//        xinxi1.put("报警时间", "2022-02-22 04:54:00");  //  TA  时间  3
//        xinxi1.put("报警结束时间", "-");
//        Array.add(xinxi1);
//        xinxi2.put("位号", "T111");
//        xinxi2.put("报警级别", "低报");
//        xinxi2.put("读值", "19.91");
//        xinxi2.put("计量单位", "℃");
//        xinxi2.put("报警时间", "2022-02-22 04:54:00");
//        xinxi2.put("报警结束时间", "-");
//        Array.add(xinxi2);
//
//        json.put("Array",Array);
//        jsonObject.put("param",json);
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");

        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction","showpoi");
        json2.put("showtype","dygroup");
        json2.put("poigroup","baojing");
        json2.put("poitype","baojing");
        jsonObject2.put("param",json2);
//        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");

        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        for (int i = 0; i < 2; i++) {
            if (i == 0) {
//                TestExampleFindAlarm testExampleFindAlarm = new TestExampleFindAlarm();
//                testExampleFindAlarm.alarm();
//                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
            } else {
                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
            }
        }
    }
}
